/*  */
#include <ctype.h>
#include "cstdlib.h"

#include "../interpreter.h"


void Cstdlib::StdIsalnum(ParseState *parser, Value *returnValue,
    Value **param, int numArgs)
{
    returnValue->val->integer = isalnum(param[0]->val->integer);
}

void Cstdlib::StdIsalpha(ParseState *parser, Value *returnValue,
    Value **param, int numArgs)
{
    returnValue->val->integer = isalpha(param[0]->val->integer);
}

void Cstdlib::StdIsblank(ParseState *parser, Value *returnValue,
    Value **param, int numArgs)
{
    int ch = param[0]->val->integer;
    returnValue->val->integer = (ch == ' ') | (ch == '\t');
}

void Cstdlib::StdIscntrl(ParseState *parser, Value *returnValue,
    Value **param, int numArgs)
{
    returnValue->val->integer = iscntrl(param[0]->val->integer);
}

void Cstdlib::StdIsdigit(ParseState *parser, Value *returnValue,
    Value **param, int numArgs)
{
    returnValue->val->integer = isdigit(param[0]->val->integer);
}

void Cstdlib::StdIsgraph(ParseState *parser, Value *returnValue,
    Value **param, int numArgs)
{
    returnValue->val->integer = isgraph(param[0]->val->integer);
}

void Cstdlib::StdIslower(ParseState *parser, Value *returnValue,
    Value **param, int numArgs)
{
    returnValue->val->integer = islower(param[0]->val->integer);
}

void Cstdlib::StdIsprint(ParseState *parser, Value *returnValue,
    Value **param, int numArgs)
{
    returnValue->val->integer = isprint(param[0]->val->integer);
}

void Cstdlib::StdIspunct(ParseState *parser, Value *returnValue,
    Value **param, int numArgs)
{
    returnValue->val->integer = ispunct(param[0]->val->integer);
}

void Cstdlib::StdIsspace(ParseState *parser, Value *returnValue,
    Value **param, int numArgs)
{
    returnValue->val->integer = isspace(param[0]->val->integer);
}

void Cstdlib::StdIsupper(ParseState *parser, Value *returnValue,
    Value **param, int numArgs)
{
    returnValue->val->integer = isupper(param[0]->val->integer);
}

void Cstdlib::StdIsxdigit(ParseState *parser, Value *returnValue,
    Value **param, int numArgs)
{
    returnValue->val->integer = isxdigit(param[0]->val->integer);
}

void Cstdlib::StdTolower(ParseState *parser, Value *returnValue,
    Value **param, int numArgs)
{
    returnValue->val->integer = tolower(param[0]->val->integer);
}

void Cstdlib::StdToupper(ParseState *parser, Value *returnValue,
    Value **param, int numArgs)
{
    returnValue->val->integer = toupper(param[0]->val->integer);
}

void Cstdlib::StdIsascii(ParseState *parser, Value *returnValue,
    Value **param, int numArgs)
{
    returnValue->val->integer = isascii(param[0]->val->integer);
}

void Cstdlib::StdToascii(ParseState *parser, Value *returnValue,
    Value **param, int numArgs)
{
    returnValue->val->integer = toascii(param[0]->val->integer);
}

/* all string.h functions */
const LibraryFunction Cstdlib::StdCtypeFunctions[] =
{
    {Cstdlib::StdIsalnum, "int isalnum(int);"},
    {Cstdlib::StdIsalpha, "int isalpha(int);"},
    {Cstdlib::StdIsblank, "int isblank(int);"},
    {Cstdlib::StdIscntrl, "int iscntrl(int);"},
    {Cstdlib::StdIsdigit, "int isdigit(int);"},
    {Cstdlib::StdIsgraph, "int isgraph(int);"},
    {Cstdlib::StdIslower, "int islower(int);"},
    {Cstdlib::StdIsprint, "int isprint(int);"},
    {Cstdlib::StdIspunct, "int ispunct(int);"},
    {Cstdlib::StdIsspace, "int isspace(int);"},
    {Cstdlib::StdIsupper, "int isupper(int);"},
    {Cstdlib::StdIsxdigit, "int isxdigit(int);"},
    {Cstdlib::StdTolower, "int tolower(int);"},
    {Cstdlib::StdToupper, "int toupper(int);"},
    {Cstdlib::StdIsascii, "int isascii(int);"},
    {Cstdlib::StdToascii, "int toascii(int);"},
    {NULL, NULL }
};

